home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3991 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.8 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Q:order of evaluation
  5. Date: Sat, 27 Jan 1996 03:00:27 GMT
  6. Organization: Netcom
  7. Message-ID: <31098f8f.11689344@nntp.ix.netcom.com>
  8. References: <4dfhlu$a33$1@mhafn.production.compuserve.com> <hamilton-1801962045570001@dialup-147.austin.io.com> <4dpcfo$293@clarknet.clark.net> <hamilton-2401960104020001@dialup-86.austin.io.com> <3108c867.40236096@nntp.ix.netcom.com> <4eb6kq$ksf@gazette.tandem.com>
  9. NNTP-Posting-Host: ix-dc17-13.ix.netcom.com
  10. X-NETCOM-Date: Fri Jan 26  7:00:40 PM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. yun_yeogirl <yyg> wrote:
  14.  
  15. > Michael M Rubenstein wrote :
  16. >         [Example:
  17. >           i = v[i++];      // the behavior is undefined
  18. >           i = 7,i++,i++;   // `i' becomes 9
  19. >           i = ++i + 1;     // the behavior is undefined
  20. >           i = i + 1;       // the value of 'i' is incremented
  21. > The first and third statement seem clear to me. I don't see why they are
  22. > undefined. I guess you made a typo here. Maybe you meant :
  23. >     i + v[i++] and i + (++i + 1).
  24. > If I am wrong, please enlighten me.
  25.  
  26. No typo.  I copied that directly from the draft.
  27.  
  28. Let's look at the first.  The only sequence points are the one at the
  29. end and the presumed one at the end of the previous expression.  There
  30. is no sequence point between the incrementing for i++ and the
  31. assignment to i for =.  The problem is that the draft (following the C
  32. standard) allows side effects to occur at any time between sequence
  33. points.  Possible valuations include both
  34.  
  35.     1.  evaluate v[i].
  36.     2.  increment i.
  37.     3.  store the result of 1 in i.
  38.  
  39. and
  40.  
  41.     1.  evaluate v[i].
  42.     2.  store the result of 1 in i.
  43.     3.  increment i.
  44.  
  45. There are other possibilities (ignoring the fact that anything is
  46. possible since the behavior is undefined).
  47.  
  48.  
  49. Michael M Rubenstein
  50.